package guiCode;

import java.sql.SQLException;

import javax.swing.JLabel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;

import secretary.defineSemester;
import teacher.*;
import flexibility.CachedRowSetTableModel;
import flexibility.uploadFileInfo;
import flexibility.userData;
import gui.CurrentCoursesIDGUI;
import gui.ManagementAssignmentsGUI;
import gui.TeacherMainMenuGUI;
import gui.assignmentsGUI;
import basic.ClientConsole;
import flexibility.uploadFileInfo;
import gui.uploadManager;

import com.sun.rowset.CachedRowSetImpl;

public class ManagementAssignmentscode {
	private assignmentsGUI asg;
	public userData T_Data = new userData();
	public TeacherMainMenuGUI tmm ;
	public ClientConsole teacherConnection=TeacherMainMenuCode.getTeacherConnection();
	public CachedRowSetImpl rs;
	public CachedRowSetImpl r1;
	int myID=TeacherMainMenuCode.getMyID();
	private CachedRowSetTableModel data;
	public static String CID;
	public Double c;//courseID
	public uploadManager uploadMngr;
	public uploadFileInfo fileInfo;
	public defineSemester semester=new defineSemester();
	int currentSem;
	
	
	public CachedRowSetImpl	getassignment(String cID)
	{
		this.CID=cID;
		getcurrassignment gca = new getcurrassignment();
        rs=gca.getcurrassignments(teacherConnection, rs, T_Data, myID,CID);
		return rs;	
	}
	
	public void update(ManagementAssignmentsGUI cc, CachedRowSetImpl crs) {
		JTableHeader tableHeader=new JTableHeader();
		
		
		try {
			cc.table.setModel(data = new CachedRowSetTableModel(crs));
			DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment(JLabel.CENTER);
			for (int i = 0; i < cc.table.getColumnCount(); i++)
				cc.table.getColumnModel().getColumn(i)
						.setCellRenderer(centerRenderer);
			cc.table.setEnabled(false);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void getAddAssignment()
	{
		getAddAssignment gaa = new getAddAssignment();
		rs=gaa.getAddass(teacherConnection, rs, T_Data,myID,CID);
		tmm.getPanel11().comboBox.addItem("  ");
	try {
		while (rs.next())
		{
			
			tmm.getPanel11().comboBox.addItem(rs.getString(1)+"   "+rs.getString(2));	
			
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	
	
	}
	public void runUploadManager(String CourseID){
		//Integer fileID;
		Integer cid=null;
		getCoursesCurrSem gcc=new getCoursesCurrSem();
		currentSem=semester.identify(0, teacherConnection, rs);
		//getcuorseID gcID = new getcuorseID();
		//r1=gcID.getcuorseID(teacherConnection, r1, T_Data, myID,CourseID);
		getSidASSid gcID = new getSidASSid();
		rs=gcID.getCid(teacherConnection, rs, T_Data, myID,CourseID);
		
		
		try {
			if(rs.next())
			{
				System.out.println("get to");
				cid =rs.getInt(1);
				
				
				
			}
			else
			{
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		fileInfo = new uploadFileInfo();
		fileInfo.setIfUpdate(false);
		fileInfo.setRole(3);
		fileInfo.setSemesterID(currentSem);///current semesterID
		fileInfo.setTeacherFileType(0);
		fileInfo.setTeacherID(myID);
		fileInfo.setcourseID(cid);
		
	
		
		uploadMngr = new uploadManager(teacherConnection, myID, fileInfo);
	}
}
